Ext.define('App.system.codeList', {
    extend      : 'Ext.panel.Panel',
    alias       : 'widget.codeListPanel',
    layout:'fit',
    autoScroll:true,
    autoHeight:true,
    initComponent : function() {
    	var grid,  selModel,  searchFlds;
    		searchFlds = new Ext.util.MixedCollection();
    		searchFlds.add('name', new Ext.form.TextField({
                name : 'name',
                fieldLabel : '用户名',
                labelAlign:'right',
                allowBlank : true,
                width : 200
            }));
        var	toolbar = new Ext.Toolbar({
            enableOverflow : true,
            items : [ {
                text : "新增",
                iconCls : 'addIcon',
                handler : function() {
                    var  codeForm = Ext.create('App.system.codeForm');
                    codeForm.show();
                    codeForm.setTitle('新增');
                }
            }, '-', {
                text : "编辑",
                iconCls : 'editIcon',
                handler : function() {
                    var sm = Ext.getCmp('codeGrid').getSelectionModel();
                    var records = sm.getSelection();
                    if (records.length <= 0) {
                        Ext.Msg.alert('错误', "未选中记录，不能修改！");
                        return;
                    }
                    var  codeForm = Ext.create('App.system.codeForm');
                    codeForm.show();
                    codeForm.setTitle('编辑');
                    codeForm.down('form').getForm().loadRecord(records[0]);

                }
            }, '-', {
                text : "删除",
                iconCls : 'deleteIcon',
                handler : function() {
                    Ext.getCmp('codeGrid').deleteRecord();
                }
            }, "->",  searchFlds.get("name"), {
                text: "搜索",
                iconCls : 'searchIcon',
                handler: function () {
                	 Ext.getCmp('codeGrid').load();
                }
            } ]
        });
        grid =	Ext.create('gridView',{
            remoteSort : true,
            forceFit: true,
            gridId :  'codeGrid',
            checkboxSelectionModel:true,
            searchFlds : searchFlds,
            entityClassName : 'com.rover.system.entity.Code',
            queryUrl : 'codeController/query.action',
            deleteUrl : 'codeController/delete.action',
            recordPk : [ "id" ],
            tbar:toolbar,
            expander:{text:'配置',
                menuDisabled: true,
                sortable: false,
                align:'center',
                xtype: 'actioncolumn',
                width: 60,
                items: [{ icon :getRootPath()+'/plug_in/smallIcon/settings.png',  tooltip: '配置该项',
                    handler: function(grid, rowIndex, colIndex) {   //rowIndex，colIndex均从0开始
                        var rec = grid.getStore().getAt(rowIndex);
                        grid.currentRowIndex = rowIndex;
                            var url=getRootPath()+"/system/codeValueList.jsp?codeId="+rec.data.id;
                        if(rec.data.isTree==1){
                            url=getRootPath()+"/system/codeValueTreeList.jsp?codeId="+rec.data.id;
                        }
                        openFrame("代码值",url);
                    } }]}
        });
    		selModel = grid.getSelectionModel();
    		selModel.on('rowselect',  function (selModel, rowIndex, record) {}
                );
        Ext.apply(this, {items:[grid]});
        this.callParent(arguments);
    } , destroy: function () {
        Ext.getCmp('codeList').destroy();
       this.destroy();
    }
});